package top.fzqblog.kotlinapp.util


import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import org.jetbrains.anko.AnkoLogger
import top.fzqblog.kotlinapp.app.KotlinApp
import top.fzqblog.kotlinapp.func.log
import java.sql.SQLException


/**
 * Created by 抽离 on 2017/11/21 0021.
 */
class DBHelper constructor(val name: String, val version: Int): SQLiteOpenHelper(KotlinApp.instance, name, null, version), AnkoLogger{

    var tableName:String = ""


    constructor(tableName: String, name: String,  version: Int):this(name,version){
        this.tableName = tableName
    }




    override fun onCreate(db: SQLiteDatabase?) {
        val  sql = "CREATE TABLE $tableName(id integer primary key autoincrement , key text not null, value text not null);"
        try {
            log("table--------------------------------create")
            db?.execSQL(sql)
        }catch (e: SQLException){
            error(e)
        }
    }


    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {

    }
}